import React from 'react';
import { connect } from 'dva';
import Redirect from 'umi/redirect';
import Authorized from '@/utils/Authorized';
import { getCookie, getRouteAuthority } from '@/utils/utils';

const AuthComponent = ({
  children,
  route = {
    routes: [],
  },
  location = {
    pathname: '',
  },
}) => {
  const { routes = [] } = route;
  const isLogin = getCookie('role') === 'admin';
  const { pathname = '' } = location;
  
  return (
    <Authorized
      // authority={getRouteAuthority(location.pathname, routes) || ''}
      authority={['admin']}
      noMatch={isLogin ? <Redirect to='/exception/403' /> : <Redirect to={`/user/login?redirect=${encodeURIComponent(pathname)}`} />}
    >
      {children}
    </Authorized>
  );
};

export default connect(({ }) => ({}))(AuthComponent);
